package cc.wfu.types.model;

import cc.wfu.types.common.Constants;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * @Author: jia-qiang ljq1024.cc
 * @desc: 统一格式返回对象
 * @Date: 2024-04-20-15:32
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class Response<T> implements Serializable {

    private String code;
    private String info;
    private T data;

    /**
     * APP 内部错误
     */
    public static <T> Response<T> APP_ERROR (String error) {
        return Response.<T>builder()
                .code(Constants.ResponseCode.APP_ERROR.getCode())
                .info(error)
                .build();
    }

    /**
     * 未知错误
     */
    public static <T> Response<T> UN_ERROR () {
        return Response.<T>builder()
                .code(Constants.ResponseCode.UN_ERROR.getCode())
                .info(Constants.ResponseCode.UN_ERROR.getInfo())
                .build();
    }

    /**
     * 参数错误
     */
    public static <T> Response<T> ILLEGAL_PARAMETER () {
        return Response.<T>builder()
                .code(Constants.ResponseCode.ILLEGAL_PARAMETER.getCode())
                .info(Constants.ResponseCode.ILLEGAL_PARAMETER.getInfo())
                .build();
    }

    /**
     * 默认错误
     */
    public static <T> Response<T> ERROR () {
        return Response.<T>builder()
                .code(Constants.ResponseCode.ERROR.getCode())
                .info(Constants.ResponseError.DEFAULT_ERROR.getInfo())
                .build();
    }

    /**
     * 成功
     */
    public static <T> Response<T> SUCCESS (T data) {
        return Response.<T>builder()
                .code(Constants.ResponseCode.SUCCESS.getCode())
                .info(Constants.ResponseCode.SUCCESS.getInfo())
                .data(data)
                .build();
    }

    /**
     * 默认成功重载
     */
    public static Response<String> SUCCESS () {
        return Response.<String>builder()
                .code(Constants.ResponseCode.SUCCESS.getCode())
                .info(Constants.ResponseCode.SUCCESS.getInfo())
                .data(Constants.ResponseError.DEFAULT_SUCCESS.getInfo())
                .build();
    }

    /**
     * 权限错误
     */
    public static <T> Response<T> TOKEN_ERROR () {
        return Response.<T>builder()
                .code(Constants.ResponseCode.TOKEN_ERROR.getCode())
                .info(Constants.ResponseCode.TOKEN_ERROR.getInfo())
                .build();
    }

}
